package com.ruoyi.map.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.map.domain.UnitSupplySurvey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.map.mapper.PersonSupplySurveyMapper;
import com.ruoyi.map.domain.PersonSupplySurvey;
import com.ruoyi.map.service.IPersonSupplySurveyService;

/**
 * 个人供给调查Service业务层处理
 *
 * @author dihang
 * @date 2023-08-16
 */
@Service
public class PersonSupplySurveyServiceImpl extends ServiceImpl<PersonSupplySurveyMapper, PersonSupplySurvey> implements IPersonSupplySurveyService
{
    @Autowired
    private PersonSupplySurveyMapper personSupplySurveyMapper;


    /**
     * 查询个人供给调查列表
     *
     *
     * @param personSupplySurvey 个人供给调查
     * @return 个人供给调查
     */
    @Override
    public List<PersonSupplySurvey> selectPersonSupplySurveyList(PersonSupplySurvey personSupplySurvey)
    {
        return baseMapper.selectPersonSupplySurveyList(personSupplySurvey);
    }


    /**查询个人供给的各个支持项目类型的数量（饼状图）
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> countByProjectType() {
        List<PersonSupplySurvey> personSupplySurveys = personSupplySurveyMapper.selectList(null);
        Map<String ,Integer>countMap=new HashMap<>();
        for (PersonSupplySurvey personSupplySurvey : personSupplySurveys) {
            String projectType = personSupplySurvey.getProjectType();
            countMap.put(projectType,countMap.getOrDefault(projectType,0)+1);
        }
        List<Map<String ,Object>>resultMap=new ArrayList<>();
        for (String projectType : countMap.keySet()) {
            Map<String ,Object>item=new HashMap<>();
            item.put("projectType",projectType);
            item.put("count",countMap.get(projectType));
            resultMap.add(item);
        }
        if (!countMap.containsKey("0")){
            Map<String, Object> aa = new HashMap<>();
            aa.put("projectType",'0');
            aa.put("count",0);
            resultMap.add(aa);
        }
        if (!countMap.containsKey("1")){
            Map<String, Object> bb = new HashMap<>();
            bb.put("projectType",'1');
            bb.put("count",0);
            resultMap.add(bb);
        }
        return resultMap;
    }

    /**
     * 查询个人供给的各个申请支持方式的数量（柱状图）
     * @return
     */
    @Override
    public List<Map<String, Object>> countBySupportWay() {
        List<PersonSupplySurvey> personSupplySurveys = personSupplySurveyMapper.selectList(null);
        Map<String ,Integer>countMap=new HashMap<>();
        for (PersonSupplySurvey personSupplySurvey : personSupplySurveys) {
            String supportWay = personSupplySurvey.getSupportWay();
            countMap.put(supportWay,countMap.getOrDefault(supportWay,0)+1);
        }
        List<Map<String, Object>> result = new ArrayList<>();
        for (String supportWay : countMap.keySet()) {
            Map<String, Object> item = new HashMap<>();
            item.put("supportWay",supportWay);
            item.put("count",countMap.get(supportWay));
            result.add(item);
        }
        if (!countMap.containsKey("0")){
            Map<String, Object> aa = new HashMap<>();
            aa.put("supportWay",'0');
            aa.put("count",0);
            result.add(aa);
        }
        if (!countMap.containsKey("1")){
            Map<String, Object> bb = new HashMap<>();
            bb.put("supportWay",'1');
            bb.put("count",0);
            result.add(bb);
        }
        if (!countMap.containsKey("2")){
            Map<String, Object> cc = new HashMap<>();
            cc.put("supportWay",'2');
            cc.put("count",0);
            result.add(cc);
        }
        if (!countMap.containsKey("3")){
            Map<String, Object> dd = new HashMap<>();
            dd.put("supportWay",'3');
            dd.put("count",0);
            result.add(dd);
        }
        return result;
    }

}
